package com.dyzx.hbb.modules.sys.controller;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.SmUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import com.alibaba.fastjson2.JSONObject;
import com.dyzx.hbb.common.base.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "01.通用接口", description = "通用接口")
@RequestMapping("sys/general")
@RestController
public class GeneralController {
    /**
     * JWT密钥 (Base64编码)
     */
    @Value("${jwt.secret:}")
    private String secret;

    @PostMapping("encrypt")
    @Operation(summary = "加密")
    public Result<String> encrypt(@RequestBody JSONObject text) {
        System.out.println(text.toJSONString());
        SymmetricCrypto sm4 = SmUtil.sm4();

        String s = sm4.encryptBase64(text.toJSONBBytes());
        return Result.ok(s);
    }
}
